Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    placeholder: {
      type: String,
      value: '搜索'
    },
    filterType: String,
    filterData: Array,
    valueKey: String,
    nodeKey: String,
    options: Array
  },
  data: {
    inputShowed: false,
    formData: {},
  },
  methods: {
    showInput() {
      this.setData({
        inputShowed: true,
      });
    },
    hideInput() {
      this.setData({
        ['formData.inputVal']: '',
        inputShowed: false,
      });
      this.triggerEvent('confirm', this.data.formData)
    },
    clearInput() {
      this.setData({
        ['formData.inputVal']: '',
      });

      this.triggerEvent('confirm', this.data.formData)
    },
    inputTyping(e) {
      this.setData({
        ['formData.inputVal']: e.detail.value,
      });
    },

    onConfirm() {
      this.triggerEvent('confirm', this.data.formData)
    },

    onSwiperChange(event) {
      this.setData({
        ['formData.swiperValue']: event.detail
      })

      this.onConfirm()
    },

    onSelectChange(event) {
      Object.keys(event.detail).forEach(item => {
        this.setData({
          [`formData.${item}`]: event.detail[item]
        })
      })

      this.onConfirm()
    }
  }
});